From: Yehuda Katz Date: Thu, 1 May 2014 00:13:50 +0000 (-0700) Subject: Map config paths onto Packages X-Git-Tag: archive/raspbian/0.35.0-2+rpi1~3^2^2^2^2^2^2^2~1100 X-Git-Url: https://dgit.raspbian.org/%22http://www.example.com/cgi/success//%22http:/www.example.com/cgi/success/?a=commitdiff_plain;h=04b91119b535b4515d4de7556d5faefaf4bc6ac3;p=cargo.git Map config paths onto Packages TODO: Move this logic into PathSource --- diff --git a/src/cargo/core/manifest.rs b/src/cargo/core/manifest.rs index c58866e11..9568f9504 100644 --- a/src/cargo/core/manifest.rs +++ b/src/cargo/core/manifest.rs @@ -24,7 +24,7 @@ struct SerializedTarget { type SerializedLibTarget = SerializedTarget; type SerializedExecTarget = SerializedTarget; -#[deriving(Decodable,Encodable,Eq,Clone)] +#[deriving(Decodable,Encodable,Eq,Clone,Show)] pub struct Manifest { pub project: ~Project, pub root: ~str, diff --git a/src/cargo/ops/cargo_compile.rs b/src/cargo/ops/cargo_compile.rs index 24141931f..dab23c4cc 100644 --- a/src/cargo/ops/cargo_compile.rs +++ b/src/cargo/ops/cargo_compile.rs @@ -21,7 +21,12 @@ use hammer::{FlagDecoder,FlagConfig,FlagConfiguration,HammerError}; use std::io; use std::io::BufReader; use std::io::process::{Process,ProcessExit,ProcessOutput,InheritFd,ProcessConfig}; -use {ToCargoError,CargoResult}; +use std::os; +use util::config; +use util::config::{all_configs,ConfigValue}; +use cargo_read_manifest = ops::cargo_read_manifest::read_manifest; +use core::Package; +use {CargoError,ToCargoError,CargoResult}; #[deriving(Decodable)] struct Options { @@ -36,7 +41,29 @@ pub fn compile() -> CargoResult<()> { let options = try!(flags::()); let manifest_bytes = try!(read_manifest(options.manifest_path)); - call_rustc(~BufReader::new(manifest_bytes.as_slice())) + let configs = try!(all_configs(os::getcwd())); + let config_paths = configs.find(&~"paths").map(|v| v.clone()).unwrap_or_else(|| ConfigValue::new()); + + let paths = match config_paths.get_value() { + &config::String(_) => return Err(CargoError::new(~"The path was configured as a String instead of a List", 1)), + &config::List(ref list) => list + }; + + println!("Paths: {}: {}", paths.len(), paths); + + let packages: Vec = paths.iter().filter_map(|path| { + let joined = Path::new(path.as_slice()).join("Cargo.toml"); + let manifest = cargo_read_manifest(joined.as_str().unwrap()); + + match manifest { + Ok(ref manifest) => Some(Package::from_manifest(manifest)), + Err(_) => None + } + }).collect(); + + println!("Packages: {}", packages); + Ok(()) + //call_rustc(~BufReader::new(manifest_bytes.as_slice())) } fn flags>() -> CargoResult { diff --git a/src/cargo/util/config.rs b/src/cargo/util/config.rs index cf72a49c5..bd572d832 100644 --- a/src/cargo/util/config.rs +++ b/src/cargo/util/config.rs @@ -13,7 +13,7 @@ pub enum Location { } #[deriving(Eq,TotalEq,Clone,Decodable)] -enum ConfigValueValue { +pub enum ConfigValueValue { String(~str), List(Vec<~str>) } @@ -48,6 +48,16 @@ pub struct ConfigValue { path: Vec<~str> } +impl ConfigValue { + pub fn new() -> ConfigValue { + ConfigValue { value: List(vec!()), path: vec!() } + } + + pub fn get_value<'a>(&'a self) -> &'a ConfigValueValue { + &self.value + } +} + impl> Encodable for ConfigValue { fn encode(&self, s: &mut S) -> Result<(), E> { s.emit_map(2, |s| {